<%--
  Created by IntelliJ IDEA.
  User: zhoufei
  Date: 2025/5/24
  Time: 21:40
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用户管理</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Microsoft YaHei', sans-serif;
        }

        body {
            background-color: #f0f2f5;
            min-height: 100vh;
        }

        /* 侧边栏样式 */
        .sidebar {
            position: fixed;
            left: 0;
            top: 0;
            width: 240px;
            height: 100vh;
            background-color: #001529;
            padding: 20px;
            color: white;
        }

        .logo {
            font-size: 24px;
            margin-bottom: 40px;
            text-align: center;
        }

        .menu-item {
            padding: 12px;
            margin: 8px 0;
            border-radius: 4px;
            cursor: pointer;
            transition: 0.3s;
        }

        .menu-item:hover {
            background-color: #1890ff;
        }

        .menu-item.active {
            background-color: #1890ff;
            position: relative;
        }

        .menu-item.active::after {
            content: "";
            position: absolute;
            right: -20px;
            top: 50%;
            transform: translateY(-50%);
            border: 10px solid transparent;
            border-right-color: #f0f2f5;
        }

        /* 主要内容区域 */
        .main-content {
            margin-left: 240px;
            padding: 20px;
        }

        /* 状态栏 */
        .status-bar {
            background-color: white;
            padding: 16px;
            border-radius: 8px;
            margin-bottom: 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        }

        /* 用户菜单 */
        .user-menu {
            position: relative;
            cursor: pointer;
            padding: 8px 12px;
            border-radius: 4px;
            transition: 0.3s;
        }

        .user-menu:hover {
            background-color: #f5f5f5;
        }

        .user-card {
            position: absolute;
            right: 0;
            top: 45px;
            width: 240px;
            background: white;
            border-radius: 8px;
            box-shadow: 0 4px 12px rgba(0,0,0,0.15);
            padding: 16px;
            display: none;
            z-index: 1000;
            animation: cardFade 0.2s ease-out;
        }

        .user-card::before {
            content: "";
            position: absolute;
            top: -8px;
            right: 20px;
            width: 16px;
            height: 16px;
            background: white;
            transform: rotate(45deg);
            box-shadow: -2px -2px 4px rgba(0,0,0,0.05);
        }

        @keyframes cardFade {
            from { opacity: 0; transform: translateY(-10px); }
            to { opacity: 1; transform: translateY(0); }
        }

        .user-info {
            display: flex;
            align-items: center;
            padding-bottom: 12px;
            border-bottom: 1px solid #eee;
        }

        .user-avatar {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            margin-right: 12px;
            background: #eee url('data:image/svg+xml;utf8,<svg viewBox="0 0 24 24" fill="%23999"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 3c1.66 0 3 1.34 3 3s-1.34 3-3 3-3-1.34-3-3 1.34-3 3-3zm0 14.2c-2.5 0-4.71-1.28-6-3.22.03-1.99 4-3.08 6-3.08 1.99 0 5.97 1.09 6 3.08-1.29 1.94-3.5 3.22-6 3.22z"/></svg>') no-repeat center;
            background-size: 60%;
        }

        .user-details {
            flex: 1;
        }

        .user-name {
            font-weight: 500;
            margin-bottom: 4px;
        }

        .user-role {
            color: #666;
            font-size: 12px;
        }

        .card-menu {
            list-style: none;
            padding: 8px 0;
        }

        .menu-item {
            padding: 12px;
            border-radius: 4px;
            cursor: pointer;
            transition: 0.2s;
        }

        .menu-item:hover {
            background: #f5f5f5;
        }

        .logout-item {
            color: #ff4d4f;
        }

        /* 统计卡片 */
        .stats-container {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
            gap: 20px;
            margin-bottom: 20px;
        }

        .stat-card {
            background-color: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        }

        /* 数据表格 */
        .data-table {
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
            overflow: hidden;
        }

        table {
            width: 100%;
            border-collapse: collapse;
        }

        th, td {
            padding: 16px;
            text-align: left;
            border-bottom: 1px solid #eee;
        }

        th {
            background-color: #fafafa;
        }

        /* 操作按钮 */
        .action-btn {
            padding: 6px 12px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            margin: 0 4px;
            transition: 0.2s;
        }

        .primary-btn {
            background-color: #1890ff;
            color: white;
        }

        .secondary-btn {
            background-color: #f5f5f5;
            color: #666;
        }

        /* 模态框 */
        .modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.5);
            align-items: center;
            justify-content: center;
            z-index: 1000;
        }

        .modal-content {
            background: white;
            padding: 24px;
            border-radius: 8px;
            min-width: 300px;
            animation: modalSlide 0.3s ease-out;
        }

        @keyframes modalSlide {
            from { transform: translateY(-20px); opacity: 0; }
            to { transform: translateY(0); opacity: 1; }
        }

        .modal-actions {
            margin-top: 20px;
            display: flex;
            gap: 12px;
            justify-content: flex-end;
        }
        .edit-modal {
            --primary-color: #1890ff;
            --text-primary: #1f1f1f;
            --text-secondary: #666;
            --border-color: #e0e0e6;
        }

        .edit-modal .modal-content {
            border-radius: 12px;
            padding: 32px;
            box-shadow: 0 8px 32px rgba(0,0,0,0.1);
            background: linear-gradient(145deg, #ffffff, #f8f9fa);
        }

        .edit-modal h3 {
            font-size: 20px;
            color: var(--text-primary);
            margin-bottom: 28px;
            padding-bottom: 16px;
            border-bottom: 1px solid var(--border-color);
            display: flex;
            align-items: center;
            gap: 12px;
        }

        .edit-modal h3::before {
            content: "✎";
            font-size: 1.2em;
            color: var(--primary-color);
        }

        .edit-modal .form-group {
            margin-bottom: 24px;
            position: relative;
        }

        .edit-modal .form-group label {
            display: block;
            margin-bottom: 8px;
            color: var(--text-secondary);
            font-size: 14px;
            font-weight: 500;
        }

        .edit-modal .form-input {
            width: 100%;
            padding: 12px 16px;
            border: 2px solid var(--border-color);
            border-radius: 8px;
            font-size: 14px;
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            background: #fff;
        }

        .edit-modal .form-input:focus {
            border-color: var(--primary-color);
            box-shadow: 0 4px 6px -1px rgba(25, 144, 255, 0.1);
        }

        .edit-modal select.form-input {
            appearance: none;
            background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
            background-repeat: no-repeat;
            background-position: right 12px center;
            background-size: 16px;
            padding-right: 36px;
        }

        /* 按钮样式升级 */
        .edit-modal .modal-actions {
            margin-top: 32px;
            display: flex;
            gap: 16px;
            justify-content: flex-end;
        }

        .edit-modal .primary-btn {
            background: var(--primary-color);
            padding: 12px 24px;
            border-radius: 8px;
            font-weight: 500;
            letter-spacing: 0.5px;
            transition: all 0.2s ease;
            min-width: 100px;
        }

        .edit-modal .primary-btn:hover {
            background: #1475d9;
            transform: translateY(-1px);
            box-shadow: 0 4px 12px -2px rgba(25, 144, 255, 0.3);
        }

        .edit-modal .secondary-btn {
            padding: 12px 24px;
            border-radius: 8px;
            border: 2px solid var(--border-color);
            background: transparent;
            color: var(--text-secondary);
            transition: all 0.2s ease;
        }

        .edit-modal .secondary-btn:hover {
            border-color: var(--primary-color);
            color: var(--primary-color);
        }

        /* 输入框动效 */
        @keyframes inputHighlight {
            from { box-shadow: 0 0 0 0 rgba(25, 144, 255, 0.3); }
            to { box-shadow: 0 0 0 4px rgba(25, 144, 255, 0); }
        }

        .edit-modal .form-input:focus {
            animation: inputHighlight 0.4s ease-out;
        }
        .container {
            max-width: 1200px;
            margin: 20px auto;
            padding: 20px;
        }

        /* 表格操作栏 */
        .table-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 16px;
        }

        .table-toolbar {
            display: flex;
            gap: 12px;
        }

        /* 表格样式 */
        .data-table {
            background: white;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
            overflow: hidden;
        }

        table {
            width: 100%;
            border-collapse: collapse;
        }

        th, td {
            padding: 16px;
            text-align: left;
            border-bottom: 1px solid #eee;
        }

        th {
            background: #fafafa;
            font-weight: 500;
        }

        .status-active {
            color: #52c41a;
            background: #f6ffed;
            padding: 4px 8px;
            border-radius: 4px;
        }

        .status-inactive {
            color: #ff4d4f;
            background: #fff1f0;
            padding: 4px 8px;
            border-radius: 4px;
        }

        /* 分页样式 */
        .pagination-container {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-top: 20px;
        }

        .pagination-controls {
            display: flex;
            align-items: center;
            gap: 12px;
        }

        .page-input-group {
            display: flex;
            gap: 8px;
            align-items: center;
        }

        .page-input {
            width: 60px;
            padding: 6px;
            border: 1px solid #ddd;
            border-radius: 4px;
        }

        .page-size-select {
            padding: 6px;
            border: 1px solid #ddd;
            border-radius: 4px;
        }

        /* 按钮样式 */
        .btn {
            padding: 8px 16px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            transition: 0.3s;
        }

        .btn-primary {
            background: #1890ff;
            color: white;
        }

        .btn-primary:hover {
            background: #1475d9;
        }

        .btn-danger {
            background: #ff4d4f;
            color: white;
        }

        .btn-danger:hover {
            background: #ff7875;
        }

        .btn-disabled {
            background: #f5f5f5;
            color: #bfbfbf;
            cursor: not-allowed;
        }

        /* 复选框样式 */
        .checkbox-group {
            display: flex;
            align-items: center;
            gap: 8px;
        }
        /* 操作栏样式 */
        .action-bar {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
            background: white;
            padding: 16px;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        }

        .primary-btn {
            background: #1890ff;
            color: white;
            padding: 8px 16px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            transition: 0.3s;
        }

        .primary-btn:hover {
            background: #1475d9;
        }

        /* 表格样式增强 */
        .data-table {
            background: white;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
            overflow: hidden;
        }

        table {
            width: 100%;
            border-collapse: collapse;
        }

        th, td {
            padding: 16px;
            text-align: left;
            border-bottom: 1px solid #eee;
        }

        th {
            background: #fafafa;
            font-weight: 500;
        }

        .status-active {
            color: #52c41a;
            background: #f6ffed;
            padding: 4px 8px;
            border-radius: 4px;
        }

        .status-inactive {
            color: #ff4d4f;
            background: #fff1f0;
            padding: 4px 8px;
            border-radius: 4px;
        }

        /* 分页样式 */
        .pagination {
            display: flex;
            justify-content: flex-end;
            gap: 8px;
            margin-top: 20px;
        }

        .page-btn {
            padding: 6px 12px;
            border: 1px solid #ddd;
            background: white;
            border-radius: 4px;
            cursor: pointer;
            transition: 0.3s;
        }

        .page-btn.active {
            background: #1890ff;
            color: white;
            border-color: #1890ff;
        }

        /* 新增用户弹窗 */
        .modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.5);
            align-items: center;
            justify-content: center;
            z-index: 1000;
        }

        .modal-content {
            background: white;
            padding: 24px;
            border-radius: 8px;
            width: 400px;
        }

        .form-group {
            margin-bottom: 16px;
        }

        .form-input {
            width: 100%;
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
            margin-top: 4px;
        }
    </style>
</head>
<body>
<!-- 侧边栏 -->
<div class="sidebar">
    <div class="logo">XXX管理系统</div>
    <div class="menu-item">仪表盘</div>
    <div class="menu-item  active">用户管理</div>
    <div class="menu-item">数据统计</div>
    <div class="menu-item">系统设置</div>
</div>

<!-- 主要内容 -->
<div class="main-content">
    <!-- 状态栏 -->
    <div class="status-bar">
        <h2>用户管理</h2>
        <div class="user-menu" id="userMenu">
            <span>管理员</span>
            <span style="margin:0 10px">|</span>
            <span>🔔</span>
            <div class="user-card" id="userCard">
                <div class="user-info">
                    <div class="user-avatar"></div>
                    <div class="user-details">
                        <div class="user-name">Admin</div>
                        <div class="user-role">超级管理员</div>
                    </div>
                </div>
                <ul class="card-menu">
                    <li class="menu-item">个人中心</li>
                    <li class="menu-item">消息通知</li>
                    <li class="menu-item">系统设置</li>
                    <li class="menu-item logout-item" id="logoutBtn">退出登录</li>
                </ul>
            </div>
        </div>
    </div>
    <div class="container">
        <!-- 表格操作栏 -->
        <div class="table-header">
            <div class="table-toolbar">
                <button class="btn btn-primary" onclick="showModal('addUserModal')">新增用户</button>
                <button class="btn btn-danger" id="batchDeleteBtn" disabled onclick="batchDelete()">批量删除</button>
            </div>
        </div>

        <div class="data-table">
            <table>
                <thead>
                <tr>
                    <th>ID</th>
                    <th>账号</th>
                    <th>用户名</th>
                    <th>注册时间</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="userTableBody">
                <!-- 数据由JavaScript动态生成 -->
                </tbody>
            </table>
        </div>

        <div class="pagination" id="pagination">
            <!-- 分页按钮由JavaScript动态生成 -->
        </div>
    </div>

    <!-- 新增用户弹窗 -->
    <div class="modal" id="addUserModal">
        <div class="modal-content">
            <h3>新增用户</h3>
            <form id="addUserForm" onsubmit="addUser(event)">
                <div class="form-group">
                    <label>用户名</label>
                    <input type="text" class="form-input" id="username" required>
                </div>
                <div class="form-group">
                    <label>初始密码</label>
                    <input type="password" class="form-input" id="password" required>
                </div>
                <div class="form-group">
                    <label>用户角色</label>
                    <select class="form-input" id="role">
                        <option value="user">普通用户</option>
                        <option value="admin">管理员</option>
                    </select>
                </div>
                <div style="margin-top: 20px; display: flex; gap: 10px;">
                    <button type="button" class="page-btn" onclick="closeModal()">取消</button>
                    <button type="submit" class="primary-btn">创建用户</button>
                </div>
            </form>
        </div>
    </div>
    </div>

</div>
<script>
        // DOM加载完成后执行
        document.addEventListener('DOMContentLoaded', () =>
        {
            // 菜单切换功能
            document.querySelectorAll('.sidebar .menu-item').forEach(item => {
                const page={"仪表盘":"home","用户管理":"userManage"};
                item.addEventListener('click', function() {
                    document.querySelectorAll('.sidebar .menu-item').forEach(i => i.classList.remove('active'));
                    this.classList.add('active');
                    document.querySelector('.main-content h2').textContent = this.textContent;
                    window.location.href = page[this.textContent]+'.jsp';
                });

            });
            // 模拟数据
            let users = Array.from({length: 35}, (_, i) => ({
                id: i + 1,
                username: `用户${i + 1}`,
                registerDate: new Date().toISOString().split('T')[0],
                status: Math.random() > 0.5 ? 'active' : 'inactive'
            }));

            // 分页配置
            const pagination = {
                currentPage: 1,
                pageSize: 10,
                get totalPages() {
                    return Math.ceil(users.length / this.pageSize)
                }
            }

            // 渲染表格
            function renderTable() {
                const start = (pagination.currentPage - 1) * pagination.pageSize
                const end = start + pagination.pageSize
                const data = users.slice(start, end)

                const tbody = document.getElementById('userTableBody')
                tbody.innerHTML = data.map(user => `
                <tr>
                    <td>${user.id}</td>
                    <td>${user.username}</td>
                    <td>${user.registerDate}</td>
                    <td>
                        <span class="status-${user.status}">
                            ${user.status == 'active' ? '正常' : '已禁用'}
                        </span>
                    </td>
                    <td>
                        <button class="primary-btn" onclick="toggleStatus(${user.id})">
                            ${user.status == 'active' ? '禁用' : '启用'}
                        </button>
                        <button class="page-btn" onclick="deleteUser(${user.id})">删除</button>
                    </td>
                </tr>
            `).join('')
            }

            // 渲染分页
            function renderPagination() {
                const paginationEl = document.getElementById('pagination')
                let html = []

                // 上一页
                html.push(`<button class="page-btn" ${pagination.currentPage == 1 ? 'disabled' : ''}
                      onclick="changePage(${pagination.currentPage - 1})">上一页</button>`)

                // 页码
                for(let i = 1; i <= pagination.totalPages; i++) {
                    html.push(`<button class="page-btn ${i == pagination.currentPage ? 'active' : ''}"
                            onclick="changePage(${i})">${i}</button>`)
                }

                // 下一页
                html.push(`<button class="page-btn" ${pagination.currentPage == pagination.totalPages ? 'disabled' : ''}
                      onclick="changePage(${pagination.currentPage + 1})">下一页</button>`)

                paginationEl.innerHTML = html.join('')
            }

            // 切换用户状态
            function toggleStatus(userId) {
                users = users.map(user =>
                    user.id == userId
                        ? {...user, status: user.status == 'active' ? 'inactive' : 'active'}
                        : user
                )
                renderTable()
            }

            // 删除用户
            function deleteUser(userId) {
                if(confirm('确定要删除该用户吗？')) {
                    users = users.filter(user => user.id !== userId)
                    if(users.length % pagination.pageSize == 0) {
                        pagination.currentPage = Math.max(1, pagination.currentPage - 1)
                    }
                    renderTable()
                    renderPagination()
                }
            }

            // 新增用户
            function addUser(e) {
                e.preventDefault()
                const newUser = {
                    id: users.length + 1,
                    username: document.getElementById('username').value,
                    registerDate: new Date().toISOString().split('T')[0],
                    status: 'active',
                    role: document.getElementById('role').value
                }
                users = [newUser, ...users]
                closeModal()
                pagination.currentPage = 1
                renderTable()
                renderPagination()
                document.getElementById('addUserForm').reset()
            }

            // 分页切换
            function changePage(page) {
                pagination.currentPage = page
                renderTable()
                renderPagination()
            }

            // 弹窗控制
            function showModal(id) {
                document.getElementById(id).style.display = 'flex'
            }

            function closeModal() {
                document.querySelectorAll('.modal').forEach(modal => {
                    modal.style.display = 'none'
                })
            }

            // 初始化
            renderTable()
            renderPagination()

            // 点击外部关闭弹窗
            window.onclick = function(e) {
                if(e.target.classList.contains('modal')) {
                    closeModal()
                }
            }

        })
</script>
</body>
</html>
